package com.example.line.step.stage;

import com.example.line.step.option.CacheIdempotentInterface;
import com.example.line.step.option.Idempotent;
import com.example.line.step.context.BaseContext;
import org.springframework.beans.factory.annotation.Autowired;

/**
 * 步骤抽象类
 * @param <T>
 */
public abstract class AbstractStage<T extends BaseContext> implements Idempotent<T>, Stage<T> {


    @Autowired
    private CacheIdempotentInterface cacheIdempotentInterface ;

    protected abstract T executeBusinessLogic(T context);


    @Override
    public T execute(T context) {

        try {

            // 1 是否存在当前步骤的缓存
            String key = getkey(context);
            cacheIdempotentInterface.existKey(key);


            // 2 执行业务逻辑
            context = executeBusinessLogic(context);


            // 3 执行完成做标记处理
            cacheIdempotentInterface.set(key);

        } catch (Exception e) {

        }

       return context;
    }



    @Override
    public String getkey(T context) {

        return "";
    }
}
